package com.ms.p2p.service.impl;


import com.ms.p2p.dao.SettingDao;
import com.ms.p2p.entity.system.Setting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 系统参数CRUD
 */
@Service
public class SettingServiceImpl {

	@Autowired
	SettingDao settingDao;
	/**
	 * 根据键查值
	 * @param nid
	 * @return
	 */
	@Cacheable(value="system",key="'valueByNid'+#nid")
	public String findValueByCode(String nid) {
		return settingDao.findValueByCode(nid);

	}
	
	/**
	 * @Title: findByType 
	 * @Description:  根据类型查参数
	 * @param type
	 * @return  List<SystemParam> 返回类型
	 */
	@Cacheable(value="system",key="'type'+#type")
	public List<Setting> findByType(int type){
		return settingDao.findListByType(type);
	}
	
	/**
	 * @Title: findAll 
	 * @Description:  所有参数列表
	 * @return  List<SystemParam> 返回类型
	 */
	public List<Setting> findAll() {
		return settingDao.findAll();

	}
	
	/**
	 * @Title: findByCode
	 * @Description:  根据nid查
	 * @param nid
	 * @return  SystemParam 返回类型
	 */
	@Cacheable(value="system",key="'nid'+#nid")
	public Setting findByCode(String nid) {
		return settingDao.findByCode(nid);

	}



	@CacheEvict(value="system",allEntries=true)
	public int insert(Setting setting) {

		return settingDao.insert(setting);

	}
	@CacheEvict(value="system",allEntries=true)
	public int update(Setting setting) {
		return settingDao.update(setting);

	}


	@CacheEvict(value="system",allEntries=true)
	public int delete(String id) {
		return settingDao.delete(id);
	}


}
